package com.bkhech.home.practice.hutool;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;

import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.List;

/**
 * @author guowm
 * @date 2023/1/30
 */
public class BasicDemo {

    public static void main(String[] args) {
        int a = 1;
        final String s = Convert.toStr(a);
        System.out.println(s);

        long[] b = {1, 2, 3, 4, 5};
        final String s1 = Convert.toStr(b);
        System.out.println(s1);

        String[] c = {"1", "2", "3", "4"};
        // 结果为整数数组
        final Integer[] toIntArray = Convert.toIntArray(c);

        String d = "2017-04-11";
        final Date date = Convert.toDate(d);
        System.out.println(date);

        Object[] e = {"a", "你", "好", "", 1};
        List<?> list = Convert.convert(List.class, a);
        //从4.1.11开始可以这么用
        list = Convert.toList(e);
        System.out.println(list);

        Object[] e1 = {"a", "你", "好", "", 1};
        List<String> arrayLists = Convert.convert(new TypeReference<List<String>>() {
        }, e1);

        arrayLists = Convert.toList(String.class, e1);
        System.out.println(arrayLists);

        // 半角和全角转换
        String f = "123456789";
        // 半角转全角：１２３４５６７８９
        String sbc = Convert.toSBC(f);

        String f1 = "１２３４５６７８９";
        final String dbc = Convert.toDBC(f1);
        // 结果为"123456789"
        System.out.println(dbc);

        // 16进制（Hex）--> HexUtil 工具类
        String g = "我是一个小小的可爱的字符串";
        final String hex = Convert.toHex(g, StandardCharsets.UTF_8);
        // e68891e698afe4b880e4b8aae5b08fe5b08fe79a84e58fafe788b1e79a84e5ad97e7aca6e4b8b2
        System.out.println(hex);
        final String raw = Convert.hexToStr(hex, StandardCharsets.UTF_8);
        // 我是一个小小的可爱的字符串
        System.out.println(raw);

        // Unicode和字符串转换
        // Result is: \u6211\u662f\u4e00\u4e2a\u5c0f\u5c0f\u7684\u53ef\u7231\u7684\u5b57\u7b26\u4e32
        final String unicode = Convert.strToUnicode(g);
        System.out.println(unicode);
        final String unicodeRaw = Convert.unicodeToStr(unicode);
        // 我是一个小小的可爱的字符串
        System.out.println(unicodeRaw);

        // 编码转换
        String h = "我不是乱码";
        final String s2 = Convert.convertCharset(h, StandardCharsets.UTF_8.name(), StandardCharsets.ISO_8859_1.name());
        final String rawS2 = Convert.convertCharset(s2, StandardCharsets.ISO_8859_1.name(), StandardCharsets.UTF_8.name());
        System.out.println(rawS2);

        // 数字转换
        final int chineseToNumber = Convert.chineseToNumber("一百一十二");
        System.out.println(chineseToNumber);

        // 原始类和包装类转换
        final Class<Integer> wrapClass = Integer.class;

        final Class<?> unWrap = Convert.unWrap(wrapClass);
        System.out.println(unWrap);

        final Class<Long> primitiveClass = long.class;
        final Class<?> wraped = Convert.wrap(primitiveClass);
        System.out.println(wraped);

    }
}
